﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace TakeColor
{
    public partial class MainFrm : Form
    {
        public MainFrm()
        {
            InitializeComponent();
            this.pb_Image.Image = Properties.Resources.jianbian.GetThumbnailImage(this.pb_Image.Width, this.pb_Image.Height, null, IntPtr.Zero);
            newImg = new Bitmap(this.pb_ShowColor.Width, this.pb_ShowColor.Height);
        }

        public Bitmap newImg;

        private void pb_Image_MouseClick(object sender, MouseEventArgs e)
        {
            Bitmap tmpImg = new Bitmap(this.pb_Image.Image);
            var color = tmpImg.GetPixel(e.Location.X, e.Location.Y);
            this.txt_Color.Text = $"#{color.Name}";

            tmpImg.Dispose();

            Graphics g = Graphics.FromImage(newImg);
            RectangleF rectangleF = new RectangleF(0, 0, newImg.Width, newImg.Height);
            Brush brush = new System.Drawing.Drawing2D.LinearGradientBrush(rectangleF, color, color, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
            g.FillRectangle(brush, rectangleF);
            this.pb_ShowColor.Image = newImg;
            this.pb_ShowColor.Image = newImg;
        }
    }
}
